package com.sce.core.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.sce.core.mongodb.model.repository.primary.PrimaryMongoObject;
import com.sce.core.mongodb.model.repository.primary.PrimaryRepository;
import com.sce.core.mongodb.model.repository.secondary.SecondaryMongoObject;
import com.sce.core.mongodb.model.repository.secondary.SecondaryRepository;

import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/mongodb")
public class MongodbController {
	
    @Autowired
    private PrimaryRepository primaryRepository;

    @Autowired
    private SecondaryRepository secondaryRepository;

	public MongodbController() {
		// TODO Auto-generated constructor stub
	}
	
	
	@ApiOperation(value = "mongodbTest",notes = "mongodbTest",nickname = "nickname",consumes = "lc")
	@RequestMapping(method = RequestMethod.POST)
	public void mongodbTest() {
		System.out.println("************************************************************");
        System.out.println("测试开始");
        System.out.println("************************************************************");
        this.primaryRepository.save(new PrimaryMongoObject(null, "第一个库的对象"));
		this.secondaryRepository.save(new SecondaryMongoObject(null, "第二个库的对象"));
		
		 List<PrimaryMongoObject> primaries = this.primaryRepository.findAll();
	        for (PrimaryMongoObject primary : primaries) {
	            System.out.println(primary.toString());
	        }
	        
        List<SecondaryMongoObject> secondaries = this.secondaryRepository.findAll();
        for (SecondaryMongoObject secondary : secondaries) {
            System.out.println(secondary.toString());
        }
        
        System.out.println("************************************************************");
        System.out.println("测试完成");
        System.out.println("************************************************************");
	}

}
